﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ZaxControls.ZaxLib.Web.UI.WebControls
{
	[DefaultProperty("Text")]
	[ToolboxData("<{0}:GridPagination runat=server></{0}:GridPagination>")]
	public class GridPagination : WebControl
	{
		#region Control Parameters

		[Bindable(true)]
		[Category("Appearance")]
		[DefaultValue("")]
		[Localizable(true)]
		public string Text
		{
			get
			{
				String s = (String)ViewState["Text"];
				return ((s == null) ? String.Empty : s);
			}

			set
			{
				ViewState["Text"] = value;
			}
		}

		public int RowsPerPage;
		public int StartRow;
		public int TotalRows;

		#endregion

		#region Render Methods

		/// <summary>
		/// Render contents of this control
		/// </summary>
		/// <param name="writer"></param>
		protected override void RenderContents(HtmlTextWriter writer)
		{
			if (RowsPerPage < TotalRows)
			{
				Table pTable = new Table();
				TableRow tr = new TableRow();
				// Calculate number of pages
				int TotalPages = TotalRows / RowsPerPage + (TotalRows % RowsPerPage == 0 ? 0 : 1);

				// Add row to table
				pTable.Controls.Add(tr);
				// Render table
				pTable.RenderControl(writer);
			}
		}// End method RenderContents

		#endregion
	}
}
